| @@ -201,15 +201,15 @@ module LiquidInterpolatable | ||
| 201 | 201 |          'concat(' << subs.join(', ') << ')' | 
| 202 | 202 | end | 
| 203 | 203 | end | 
| 204 | - | |
| 204 | + | |
| 205 | 205 | def regex_replace(input, regex, replacement = ''.freeze) | 
| 206 | 206 | input.to_s.gsub(Regexp.new(regex), replacement.to_s) | 
| 207 | 207 | end | 
| 208 | - | |
| 208 | + | |
| 209 | 209 | def regex_replace_first(input, regex, replacement = ''.freeze) | 
| 210 | 210 | input.to_s.sub(Regexp.new(regex), replacement.to_s) | 
| 211 | 211 | end | 
| 212 | - | |
| 212 | + | |
| 213 | 213 | private | 
| 214 | 214 |  | 
| 215 | 215 | def logger | 
| @@ -177,23 +177,25 @@ describe LiquidInterpolatable::Filters do | ||
| 177 | 177 |          expect(@agent.interpolated['long_url']).to eq('http://2many.x/6') | 
| 178 | 178 | end | 
| 179 | 179 | end | 
| 180 | - | |
| 181 | - describe 'regex replace' do | |
| 182 | -      let(:agent) { Agents::InterpolatableAgent.new(name: "test") } | |
| 183 | - | |
| 184 | - it 'should replace the first occurrence of a string using regex' do | |
| 185 | - agent.interpolation_context['something'] = 'foobar foobar' | |
| 186 | -        agent.options['cleaned'] = '{{ something | regex_replace_first: "\S+bar", "foobaz"  }}' | |
| 187 | -        expect(agent.interpolated['cleaned']).to eq('foobaz foobar') | |
| 188 | - end | |
| 180 | + end | |
| 189 | 181 |  | 
| 190 | - it 'should replace the all occurrences of a string using regex' do | |
| 191 | - agent.interpolation_context['something'] = 'foobar foobar' | |
| 192 | -        agent.options['cleaned'] = '{{ something | regex_replace: "\S+bar", "foobaz"  }}' | |
| 193 | -        expect(agent.interpolated['cleaned']).to eq('foobaz foobaz')  | |
| 194 | - end | |
| 195 | - | |
| 182 | + describe 'regex_replace_first' do | |
| 183 | +    let(:agent) { Agents::InterpolatableAgent.new(name: "test") } | |
| 184 | + | |
| 185 | + it 'should replace the first occurrence of a string using regex' do | |
| 186 | + agent.interpolation_context['something'] = 'foobar foobar' | |
| 187 | +      agent.options['cleaned'] = '{{ something | regex_replace_first: "\S+bar", "foobaz"  }}' | |
| 188 | +      expect(agent.interpolated['cleaned']).to eq('foobaz foobar') | |
| 189 | + end | |
| 190 | + end | |
| 191 | + | |
| 192 | + describe 'regex_replace' do | |
| 193 | +    let(:agent) { Agents::InterpolatableAgent.new(name: "test") } | |
| 194 | + | |
| 195 | + it 'should replace the all occurrences of a string using regex' do | |
| 196 | + agent.interpolation_context['something'] = 'foobar foobar' | |
| 197 | +      agent.options['cleaned'] = '{{ something | regex_replace: "\S+bar", "foobaz"  }}' | |
| 198 | +      expect(agent.interpolated['cleaned']).to eq('foobaz foobaz') | |
| 196 | 199 | end | 
| 197 | - | |
| 198 | 200 | end | 
| 199 | 201 | end |